Azure Firewall/Script - Migrate Fortigate config to Azure Firewall policy/read_fortigate_config.py (343 lines of code) (raw):
��# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# R e a d s a f o r t i g a t e c o n f i g a n d e x p o r t s c o m m a n d s t o a p p e n d t h e r u l e s t o a n e x i s t i n g A z F W P o l i c y
#
# E x a m p l e :
# p y t h o n . / r e a d _ f o r t i g a t e _ c o n f i g . p y - - f i l e . / f o r t i g a t e _ o u t p u t . t x t - - f o r m a t j s o n
# a z n e t w o r k f i r e w a l l p o l i c y r u l e - c o l l e c t i o n - g r o u p c o l l e c t i o n r u l e a d d - - n a m e 1 0 7 3 7 4 2 0 0 0 - - s o u r c e - a d d r e s s e s 1 0 . 1 5 . 5 . 2 0 / 3 2 1 0 . 1 5 . 5 . 4 0 / 3 2 1 0 . 1 5 . 5 . 3 0 / 3 2 1 0 . 1 5 . 5 . 5 0 / 3 2 1 0 . 5 . 2 2 . 1 4 0 / 3 2 1 0 . 5 . 2 2 . 1 4 5 / 3 2 1 0 . 5 . 2 2 . 1 5 0 / 3 2 1 0 . 5 . 2 2 . 1 5 5 / 3 2 - - d e s t i n a t i o n - a d d r e s s e s 1 0 . 1 0 . 4 0 . 2 1 / 3 2 1 0 . 1 0 . 4 0 . 2 2 / 3 2 - - p r o t o c o l s t c p u d p - - d e s t i n a t i o n - p o r t s 2 8 8 3 3 4 3 4
# a z n e t w o r k f i r e w a l l p o l i c y r u l e - c o l l e c t i o n - g r o u p c o l l e c t i o n r u l e a d d - - n a m e 1 0 7 3 7 4 2 0 4 1 - - s o u r c e - a d d r e s s e s 1 0 . 1 5 . 5 . 4 0 / 3 2 1 0 . 1 5 . 5 . 5 0 / 3 2 1 0 . 5 . 2 2 . 1 4 0 / 3 2 1 0 . 5 . 2 2 . 1 5 0 / 3 2 - - d e s t i n a t i o n - a d d r e s s e s 1 0 . 1 0 . 4 0 . 2 1 / 3 2 1 0 . 1 0 . 4 0 . 2 2 / 3 2 - - p r o t o c o l s t c p u d p - - d e s t i n a t i o n - p o r t s 2 2
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
i m p o r t r e
i m p o r t s y s
i m p o r t r a n d o m
i m p o r t s t r i n g
i m p o r t a r g p a r s e
i m p o r t s o c k e t
f r o m t y p e s i m p o r t p r e p a r e _ c l a s s
d e f n e t m a s k _ t o _ c i d r ( m _ n e t m a s k ) :
t r y :
i p = s o c k e t . g e t h o s t b y n a m e ( d )
i f i p :
r e t u r n i p
e l s e :
r e t u r n ( s u m ( [ b i n ( i n t ( b i t s ) ) . c o u n t ( "